public class EditMapObjectOperation extends MapMemory
{

    private static final long serialVersionUID = 5459787570243008914L;
    private MapObject newObject;
    private int mapObjectArrayLoc;
    private boolean isEdit = false;

    public EditMapObjectOperation(MapObject oldObject, MapObject newObject, MapPanel enclosingPanel)
    {
	super(oldObject, enclosingPanel);
	this.newObject = newObject;

	// the new object is the object in the array, so we get its position
	this.mapObjectArrayLoc = this.enclosingPanel.getMap().getMapObjects().indexOf(newObject);
	System.out.println(this.mapObjectArrayLoc);
    }

    @Override
    public void undo()
    {
	System.out.println("Value: " + this.value + " index: " + this.enclosingPanel.getMap().getMapObjects().indexOf(this.value) + " NewObject: " + this.newObject + " index: " + this.enclosingPanel.getMap().getMapObjects().indexOf(this.newObject));
	
	this.enclosingPanel.setDisplayMap(((MapObject) this.value).getMap());

	// if index of the object is -1 then the object is not in the arrayList
	// and we know that a deletionOperation was performed
	if (this.enclosingPanel.getMap().getMapObjects().indexOf(this.newObject) != -1)
	{
	    System.out.println("go: " + this.mapObjectArrayLoc);
	    this.isEdit = true;
	    this.enclosingPanel.getMap().getMapObjects().remove(this.mapObjectArrayLoc);
	}
	this.enclosingPanel.getMap().getMapObjects().add(this.mapObjectArrayLoc, (MapObject) this.value);
    }

    @Override
    public void redo()
    {
	this.enclosingPanel.setDisplayMap(((MapObject) this.value).getMap());
	this.enclosingPanel.getMap().getMapObjects().remove(this.mapObjectArrayLoc);

	if (this.isEdit)
	{
	    this.enclosingPanel.getMap().getMapObjects().add(this.mapObjectArrayLoc, this.newObject);
	}
    }
}
